/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;

/**
 * @author USER
 */
public class MobileMonstersMIDlet extends MIDlet implements CommandListener {

    public static int CLICKED = 0;
    public int currentPage = 0;
    protected Display display;      //reference to display
    private Command cmdExit;
    //canvas
    private MenuCanvas menuCanvas;
    private ScreenOne screenOne;
    private ScreenTwo screenTwo;
    private ScreenThree screenThree;
    private ScreenFour screenFour;

    public MobileMonstersMIDlet() {
        display = Display.getDisplay(this);

        // create game canvas and exit command
        /*
        if ((grassCanvas = new GrassCanvas(this)) != null) {
        //cmdExit = new Command("Exit", Command.EXIT, 0);
        //grassCanvas.addCommand(cmdExit);
        //grassCanvas.setCommandListener(this);
        }
         * 
         */
    }

    public void startApp() {
        showMenuCanvas();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        //menuCanvas.stop();
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdExit) {
            destroyApp(true);
            notifyDestroyed();
        }
    }

    public void exit() {        
        menuCanvas = null;
        screenOne = null;
        screenTwo = null;
        screenThree = null;
        screenFour = null;
          
        destroyApp(true);
        notifyDestroyed();
    }

    public void showMenuCanvas() {
        CLICKED = 0;
        //menuCanvas.stop();
        menuCanvas = new MenuCanvas(this);
        display.setCurrent(menuCanvas);
        menuCanvas.start();
    }

    public void beforeShow(int no) {
        if (no == 0) {
            menuCanvas.stop();
            menuCanvas = null;
            showScreen(1);
        } else if (no == 1) {
            screenOne.stop();
            screenOne = null;
            showScreen(2);
        } else if (no == 2) {
            screenTwo.stop();
            screenTwo = null;
            showScreen(3);
        } else if (no == 3) {
            screenThree.stop();
            screenThree = null;
            showScreen(4);
        } else if (no == 4) {
            screenFour.stop();
            screenFour = null;
            showScreen(0);
        }
    }

    private void showScreen(int no) {
        if (no == 0) { // goto screenOne
            currentPage = 0;
            menuCanvas = new MenuCanvas(this);
            display.setCurrent(menuCanvas);
            menuCanvas.start();
            CLICKED = 0;
        } else if (no == 1) { // goto screenOne
            currentPage = 1;
            screenOne = new ScreenOne(this);
            display.setCurrent(screenOne);
            screenOne.start();
            CLICKED = 0;
        } else if (no == 2) { // goto screenTwo
            currentPage = 2;
            screenTwo = new ScreenTwo(this);
            screenTwo.setCommandListener(this);
            display.setCurrent(screenTwo);
            screenTwo.start();
            CLICKED = 0;
        } else if (no == 3) { // goto screenThree
            currentPage = 3;
            screenThree = new ScreenThree(this);
            screenThree.setCommandListener(this);
            display.setCurrent(screenThree);
            screenThree.start();
            CLICKED = 0;
        } else if (no == 4) { // goto screenFour
            currentPage = 4;
            screenFour = new ScreenFour(this);
            screenFour.setCommandListener(this);
            display.setCurrent(screenFour);
            screenFour.start();
            CLICKED = 0;
        }
    }
}
